package cglgu.trellis.chado.das2.cglgu.db;

/*
 * $Id: CglguDbUtilFactory.java 191 2011-03-27 00:38:22Z sundaram.georgetown@gmail.com $
 * $Author: sundaram.georgetown@gmail.com $
 * $Date: 2011-03-27 00:38:22 +0000 (Sun, 27 Mar 2011) $
 * $Rev: 191 $
 * $HeadURL: http://genomancer.googlecode.com/svn/branches/gu-dev-branch/tengcha/src/cglgu/trellis/chado/das2/cglgu/db/CglguDbUtilFactory.java $
 */

import cglgu.trellis.chado.das2.cglgu.db.CglguMysqlDbUtil;
import cglgu.trellis.chado.das2.cglgu.db.CglguOracleDbUtil;
import cglgu.trellis.chado.das2.cglgu.db.CglguSybaseDbUtil;
import cglgu.trellis.chado.das2.cglgu.db.CglguPostgresqlDbUtil;
import cglgu.trellis.chado.das2.ant.db.AntMysqlDbUtil;
import cglgu.trellis.chado.das2.ant.db.AntOracleDbUtil;
import cglgu.trellis.chado.das2.ant.db.AntSybaseDbUtil;
import cglgu.trellis.chado.das2.ant.db.AntSybaseDbUtil;
import cglgu.trellis.chado.das2.bee.db.BeeMysqlDbUtil;
import cglgu.trellis.chado.das2.bee.db.BeeOracleDbUtil;
import cglgu.trellis.chado.das2.bee.db.BeeSybaseDbUtil;
import cglgu.trellis.chado.das2.bee.db.BeePostgresqlDbUtil;
import cglgu.trellis.chado.das2.bovine.db.BovineMysqlDbUtil;
import cglgu.trellis.chado.das2.bovine.db.BovineOracleDbUtil;
import cglgu.trellis.chado.das2.bovine.db.BovineSybaseDbUtil;
import cglgu.trellis.chado.das2.bovine.db.BovinePostgresqlDbUtil;
import cglgu.trellis.chado.das2.wasp.db.WaspMysqlDbUtil;
import cglgu.trellis.chado.das2.wasp.db.WaspOracleDbUtil;
import cglgu.trellis.chado.das2.wasp.db.WaspSybaseDbUtil;
import cglgu.trellis.chado.das2.wasp.db.WaspPostgresqlDbUtil;

public class CglguDbUtilFactory  {

    private static CglguDbUtilFactory instance = null;
    private boolean useMultiQuery = false;

    protected CglguDbUtilFactory() {

    }

    public static CglguDbUtilFactory getInstance(){

	if (instance == null){
	    instance = new CglguDbUtilFactory();
	}

	return instance;
    }

    public static CglguDbUtil create(String project, String databaseType, String username, String password, String host, String database, boolean useMultiQry){

	CglguDbUtil dbutil;

	int fatalCtr = 0;

	if (project == null){
       	    System.err.println("project was not defined");
	    fatalCtr++;
	}
	if (databaseType == null){
	    System.err.println("databaseType was not defined");
	    fatalCtr++;
	}
	if (username == null){
	    System.err.println("username was not defined!");
	    fatalCtr++;
	}
	if (password == null){
	    System.err.println("password was not defined!");
	    fatalCtr++;
	}
	if (database == null){
	    System.err.println("database was not defined!");
	    fatalCtr++;
	}

	if (fatalCtr > 0){
	    System.err.println("Required parameters were not defined!");
	    System.exit(1);
	}

	if (project.toLowerCase().equals("ant")){

	    if (databaseType.toLowerCase().equals("mysql")){

		dbutil = AntMysqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("oracle")){
		dbutil = AntOracleDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("postgresql")){
		dbutil = AntPostgresqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("sybase")){
		dbutil = AntSybaseDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else {
		System.err.println("Unsupport database type " + databaseType);
		System.exit(1);
	    }
	}
	else if (project.toLowerCase().equals("bee")){

	    if (databaseType.toLowerCase().equals("mysql")){

		dbutil = BeeMysqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("oracle")){
		dbutil = BeeOracleDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("postgresql")){
		dbutil = BeePostgresqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("sybase")){
		dbutil = BeeSybaseDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else {
		System.err.println("Unsupport database type " + databaseType);
		System.exit(1);
	    }
	}
	else if (project.toLowerCase().equals("bovine")){

	    if (databaseType.toLowerCase().equals("mysql")){

		dbutil = BovineMysqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("oracle")){
		dbutil = BovineOracleDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("postgresql")){
		dbutil = BovinePostgresqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("sybase")){
		dbutil = BovineSybaseDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else {
		System.err.println("Unsupport database type " + databaseType);
		System.exit(1);
	    }
	}
	else if (project.toLowerCase().equals("wasp")){

	    if (databaseType.toLowerCase().equals("mysql")){

		dbutil = WaspMysqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("oracle")){
		dbutil = WaspOracleDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("postgresql")){
		dbutil = WaspPostgresqlDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else if (databaseType.toLowerCase().equals("sybase")){
		dbutil = WaspSybaseDbUtil.getInstance(username, password, database, host, useMultiQry);
	    }
	    else {
		System.err.println("Unsupport database type " + databaseType);
		System.exit(1);
	    }
	}
	else {
	    System.err.println("Unsupported project " + project);
	    System.exit(1);
	}
    }
}